package com.da.javatest.leetCode;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

/**
 * @author chenlida
 * @date 2018/12/14 16:10
 * @description
 */
public class Code950 {
    public static void main(String[] args) {
        new Code950().deckRevealedIncreasing(new int[] {17, 13, 11, 2, 3, 5, 7});
    }

    public int[] deckRevealedIncreasing(int[] deck) {
        if (deck.length == 1) {
            return new int[] {1};
        }
        Arrays.sort(deck);
        Deque<Integer> r = new ArrayDeque<>();
        r.addFirst(deck[deck.length - 1]);
        r.addFirst(deck[deck.length - 2]);
        for (int i = deck.length - 3; i >= 0; i--) {
            r.addFirst(r.pollLast());
            r.addFirst(deck[i]);
        }
        int[] result = new int[deck.length];
        int i = 0;
        for (Integer integer : r) {
            result[i++] = integer;
        }
        return result;
    }
}
